home *** CD-ROM | disk | FTP | other *** search
- /* File: LibraryManagerClasses.h
-
- Contains: Declarations for ASLM classes
-
- Copyright: © 1991-1995 by Apple Computer, Inc., all rights reserved.
-
-
- */
-
- #ifndef __LIBRARYMANAGERCLASSES__
- #define __LIBRARYMANAGERCLASSES__
-
- #ifndef __LIBRARYMANAGER__
- #include <LibraryManager.h>
- #endif
-
- /*******************************************************************************
- ** Forward class declarations
- ********************************************************************************/
-
- #ifdef __cplusplus
- class TOperation;
- class TStandardPool;
- class TTraceLog;
- class TTaskScheduler;
- class TArbitrator;
- class TTime;
- class TPoolNotifier;
- class TRequestToken;
- class TToken;
- #else
- typedef void TOperation;
- typedef void TTraceLog;
- typedef void TArbitrator;
- typedef void TTaskScheduler;
- #endif
-
- /*******************************************************************************
- ** Some typedefs and enums
- ********************************************************************************/
-
- //
- // PointerType is mainly used for the TCollection::DeleteAll method so the collection
- // knows what type of objects are in the collection so it can do the proper cast
- // and call the destructor (if it really is an object).
- //
- typedef int PointerType;
-
- #define kVoidPointer ((PointerType)0) /* a non-object pointer */
- #define kTDynamicPointer ((PointerType)1) /* SingleObject with vtable first */
- #define kTSCDynamicPointer ((PointerType)1) /* subclass of TSCDynamic */
- #define kTSCPointer ((PointerType)2) /* A Symantec C++ Object */
- #define kTStdDynamicPointer ((PointerType)3) /* non-SingleObject with vtable first */
-
- typedef unsigned long EventCode;
-
- #define kTokenNotification ((EventCode)0x40000001)
- #define kLowPoolMemoryEvent ((EventCode)0x40000002)
- #define kHighPoolMemoryEvent ((EventCode)0x40000003)
- #define kDownsizePoolEvent ((EventCode)0x40000004)
- #define kDeathEvent ((EventCode)0x40000005)
-
- typedef void (* _CDECL ProcessProcPtr)(TOperation*);
-
- typedef unsigned long (* _CDECL HashProcPtr)(const void*);
- typedef Boolean (* _CDECL IsEqualProcPtr)(const void* ref, const void* toComp);
- typedef int (* _CDECL CompareProcPtr)(const void* ref, const void* toComp);
-
- // Below is a typedef for a pointer to a notify method for an object. Ignore the
- // fact the the typedef claims that it needs to be a TDynamic method. It can be
- // any kind of class. The only caveat is that if the NotifyMethod is a virtual
- // function, the vtable for the object must be the first field of the object.
- // You can force the vtable to be first by creating a base class that has atleast
- // one virtual function and no data members, like TDynamic does.
- #ifdef __cplusplus
- typedef void (TDynamic::* _CDECL NotifyMethodPtr)(EventCode, OSErrParm, void* notifyData);
- typedef NotifyMethodPtr NotifyMethod;
- #endif
- typedef void (* _CDECL NotifyProcPtr)(void* refPtr, EventCode, OSErrParm, void* notifyData);
-
- //
- // These are for compatibility with ASLM 1.1
- //
- typedef ProcessProcPtr ProcessProc;
- typedef HashProcPtr HashProc;
- typedef IsEqualProcPtr IsEqualProc;
- typedef CompareProcPtr CompareProc;
- typedef NotifyProcPtr NotifyProc;
-
- /*******************************************************************************
- ** Some "C" Global routines
- ********************************************************************************/
-
- #ifdef __cplusplus
- extern "C"
- {
- #endif
- TTraceLog* GetGlobalTraceLog();
- void SetGlobalTraceLog(TTraceLog*);
- void Trace(const char *formatStr, ...);
-
- TArbitrator* GetGlobalArbitrator();
- TTaskScheduler* GetGlobalTaskScheduler();
- void DestroyPointer(void*, PointerType);
-
- #if GENERATING68K
- TLibraryManager* GetClientFromWorld(GlobalWorld); /* get client which owns the specified global world */
- #endif
- #ifdef __cplusplus
- }
- #endif
-
- #ifdef __cplusplus
-
- /*******************************************************************************
- ** TMacSemaphore class
- **
- ** Since threads don't really exist on the Macintosh, these semaphores are
- ** done by shutting interrupts off to guarantee exclusivity. Therefore,
- ** the rule is - never hold one very long, since on the Macintosh
- ** it will degrade performance if you do.
- ********************************************************************************/
-
- #define kTMacSemaphoreID "!$sema,1.2"
-
- class TMacSemaphore : public TDynamic
- {
- public:
- _CDECL TMacSemaphore();
- virtual ~_CDECL TMacSemaphore();
-
- virtual void _CDECL Grab();
- virtual void _CDECL Release();
- virtual Boolean _CDECL GrabNoWait();
-
- private:
- TMacSemaphore(const TMacSemaphore&);
- void operator=(const TMacSemaphore&);
-
- short fSaveLevel;
- short fCount;
- };
-
- /*******************************************************************************
- ** CLASS TMatchObject
- **
- ** This object is the base class for any object which "knows" how
- ** to hash a specific object, as well as how to compare a
- ** 2nd object to the specific object.
- ********************************************************************************/
-
- #define kTMatchObjectID "!$mobj,1.2"
-
- class TMatchObject : public TDynamic
- {
- public:
- virtual ~_CDECL TMatchObject();
-
- // Default implementation is to return 0
- virtual unsigned long _CDECL Hash() const;
- // Default implementation is to compare
- // address of "this" with address of the object
- virtual short _CDECL Compare(const void*) const;
- // Default implementation is to call Compare
- virtual Boolean _CDECL IsEqual(const void*) const;
-
- protected:
- _CDECL TMatchObject();
- };
-
- /*******************************************************************************
- ** CLASS TProcMatchObject
- **
- ** This is a TMatchObject which takes a reference pointer and pointers to "C"
- ** functions to do the matching/hashing job.
- ********************************************************************************/
-
- #define kTProcMatchObjectID "!$pmob,1.2"
-
- class TProcMatchObject : public TMatchObject
- {
- public:
- _CDECL TProcMatchObject(const void* ref, HashProcPtr = 0,
- CompareProcPtr = 0, IsEqualProcPtr = 0);
- virtual ~_CDECL TProcMatchObject();
-
- virtual unsigned long _CDECL Hash() const;
- virtual short _CDECL Compare(const void*) const;
- virtual Boolean _CDECL IsEqual(const void*) const;
-
- void SetReferencePointer(const void*);
- void SetHashProc(HashProcPtr);
- void SetCompareProc(CompareProcPtr);
- void SetIsEqualProc(IsEqualProcPtr);
-
- const void* GetReferencePointer() const;
- HashProcPtr GetHashProc() const;
- CompareProcPtr GetCompareProc() const;
- IsEqualProcPtr GetIsEqualProc() const;
-
- private:
- const void* fRef;
- HashProcPtr fHashProc;
- CompareProcPtr fCompareProc;
- IsEqualProcPtr fIsEqualProc;
- };
-
-
- /* -------------------------------------------------------------------------
- Inline methods for TProcMatchObject
- ------------------------------------------------------------------------- */
-
- inline void TProcMatchObject::SetReferencePointer(const void* ref)
- {
- fRef = ref;
- }
-
- inline void TProcMatchObject::SetHashProc(HashProcPtr proc)
- {
- fHashProc = proc;
- }
-
- inline void TProcMatchObject::SetCompareProc(CompareProcPtr proc)
- {
- fCompareProc = proc;
- }
-
- inline void TProcMatchObject::SetIsEqualProc(IsEqualProcPtr proc)
- {
- fIsEqualProc = proc;
- }
-
- inline const void* TProcMatchObject::GetReferencePointer() const
- {
- return fRef;
- }
-
- inline HashProcPtr TProcMatchObject::GetHashProc() const
- {
- return fHashProc;
- }
-
- inline CompareProcPtr TProcMatchObject::GetCompareProc() const
- {
- return fCompareProc;
- }
-
- inline IsEqualProcPtr TProcMatchObject::GetIsEqualProc() const
- {
- return fIsEqualProc;
- }
-
- /*******************************************************************************
- ** CLASS THashObject
- **
- ** This object is the base class for any object which "knows" how
- ** to hash another object.
- ********************************************************************************/
-
- #define kTHashObjectID "!$hobj,1.2"
-
- class THashObject : public TDynamic
- {
- public:
- virtual ~_CDECL THashObject();
-
- virtual unsigned long _CDECL Hash(const void*) const = 0;
-
- protected:
- _CDECL THashObject();
- };
-
- /*******************************************************************************
- ** CLASS TProcHashObject
- **
- ** This is a THashObject which uses a "C" Procedure to hash objects.
- ********************************************************************************/
-
- #define kTProcHashObjectID "!$phob,1.2"
-
- class TProcHashObject : public THashObject
- {
- public:
- _CDECL TProcHashObject(HashProcPtr);
- virtual ~_CDECL TProcHashObject();
-
- virtual unsigned long _CDECL Hash(const void*) const;
-
- void SetHashProc(HashProcPtr);
- HashProcPtr GetHashProc() const;
-
- private:
- HashProcPtr fHashProc;
- };
-
- /* -------------------------------------------------------------------------
- Inline methods for TProcHashObject
- ------------------------------------------------------------------------- */
-
- inline void TProcHashObject::SetHashProc(HashProcPtr proc)
- {
- fHashProc = proc;
- }
-
- inline HashProcPtr TProcHashObject::GetHashProc() const
- {
- return fHashProc;
- }
-
- /*******************************************************************************
- ** CLASS TIterator
- **
- ** This class Iterates through a collection of objects. Since
- ** collections are "thread-safe", when the Next() method returns
- ** NULL, call IterationComplete(). If it returns true, then you were
- ** returned NULL because the iterator was done. Otherwise, you were
- ** returned NULL because the underlying collection changed.
- ** RemoveCurrentObject will return false if the collection changed
- ** before the remove could be done.
- ********************************************************************************/
-
- #define kTIteratorID "!$iter,1.2"
-
- class TIterator : public TDynamic
- {
- public:
- virtual ~_CDECL TIterator();
-
- virtual void _CDECL Reset() = 0;
- virtual void* _CDECL Next() = 0;
-
- virtual Boolean _CDECL IterationComplete() const = 0;
- virtual Boolean _CDECL RemoveCurrentObject() = 0;
-
- void SetMatchObject(TMatchObject*);
- TMatchObject* GetMatchObject() const;
-
- protected:
- _CDECL TIterator();
-
- private:
- TMatchObject* fMatcher;
- };
-
- /* -------------------------------------------------------------------------
- Inline methods for TIterator
- ------------------------------------------------------------------------- */
-
- inline void TIterator::SetMatchObject(TMatchObject* theMatcher)
- {
- fMatcher = theMatcher;
- }
-
- inline TMatchObject* TIterator::GetMatchObject() const
- {
- return fMatcher;
- }
-
- /*******************************************************************************
- ** CLASS TCollection
- **
- ** This class defines the framework for all collections.
- ********************************************************************************/
-
- #define kTCollectionID "!$coll,1.2"
-
- class TCollection : public TDynamic
- {
- public:
- virtual ~_CDECL TCollection();
-
- size_t Count() const;
- Boolean IsEmpty() const;
- virtual TIterator* _CDECL CreateIterator(TStandardPool*) = 0;
-
- virtual OSErr _CDECL Add(void*);
- virtual OSErr _CDECL AddUnique(void*, const TMatchObject&);
- virtual OSErr _CDECL AddUnique(void*);
-
- virtual void _CDECL RemoveAll();
- virtual void _CDECL DeleteAll(PointerType = kTDynamicPointer);
- virtual void* _CDECL Remove(const TMatchObject&) = 0;
- virtual Boolean _CDECL Remove(void*) = 0;
- virtual void* _CDECL Member(const TMatchObject&) = 0;
- virtual Boolean _CDECL Member(const void*) = 0;
-
- virtual void* _CDECL GetIndexedObject(size_t) const;
- void* operator[](size_t);
-
- long GetSeed() const;
- void Grab();
- void Release();
-
- protected:
- _CDECL TCollection();
- virtual OSErr _CDECL PrivateAdd(void*, long) = 0;
- virtual void _CDECL KillAll(BooleanParm ifDel, PointerType) = 0;
-
- long fSeed;
- size_t fCount;
- TMacSemaphore fSemaphore;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TCollection
- ----------------------------------------------------------------- */
-
- inline size_t TCollection::Count() const
- {
- return fCount;
- }
-
- inline Boolean TCollection::IsEmpty() const
- {
- return fCount == 0;
- }
-
- inline void* TCollection::operator[](size_t idx)
- {
- return GetIndexedObject(idx);
- }
-
- inline long TCollection::GetSeed() const
- {
- return fSeed;
- }
-
- inline void TCollection::Grab()
- {
- (&fSemaphore)->Grab();
- }
-
- inline void TCollection::Release()
- {
- (&fSemaphore)->Release();
- }
-
- /*******************************************************************************
- ** CLASS TLink
- **
- ** This class implements a link object which can be placed on a linked
- ** list. It is totally non-virtual since it is a trivial class and
- ** to keep it at 8 bytes in size.
- ********************************************************************************/
-
- class TLink
- {
- public:
- TLink(void* value);
- TLink(TLink* link, void* value);
- TLink(BooleanParm);
- TLink();
- ~TLink();
-
- void* operator new(size_t size, TMemoryPool*); // default size, from a pool
- void* operator new(size_t); // from default pool
- void operator delete(void* mem) {SLMDeleteOperator(mem);};
-
- void SetNext(TLink* link);
- TLink* GetNext() const;
-
- void* GetValue() const;
- void SetValue(void*);
-
- void Append(TLink* newLink); // append newLink after this
- void Remove(TLink* previous); // remove nextLink from list
-
- private:
- TLink* fNext;
- void* fValue;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TLink
- ----------------------------------------------------------------- */
-
- inline void* TLink::operator new(size_t size, TMemoryPool* thePool)
- {
- return SLMNewOperator(size, thePool);
- }
-
- inline void* TLink::operator new(size_t size)
- {
- return SLMNewOperator(size, NULL);
- }
-
- inline TLink::TLink(BooleanParm)
- {}
-
- inline TLink::TLink()
- {
- fNext = NULL;
- fValue = NULL;
- }
-
- inline TLink::TLink(void* value)
- {
- fNext = NULL;
- fValue = value;
- }
-
- inline TLink::TLink(TLink* link, void* value)
- {
- fNext = link;
- fValue = value;
- }
-
- inline TLink::~TLink()
- {
- fNext = NULL;
- fValue = NULL;
- }
-
- inline void TLink::SetNext(TLink* link)
- {
- fNext = link;
- }
-
- inline TLink* TLink::GetNext() const
- {
- return fNext;
- }
-
- inline void* TLink::GetValue() const
- {
- return fValue;
- }
-
- inline void TLink::SetValue(void* obj)
- {
- fValue = obj;
- }
-
- inline void TLink::Append(TLink* newLink)
- {
- newLink->SetNext(fNext);
- fNext = newLink;
- }
-
- inline void TLink::Remove(TLink* previous)
- {
- TLink* link = previous->GetNext();
- previous->SetNext(fNext);
- link->SetNext(NULL);
- }
-
- /*******************************************************************************
- ** CLASS TPriorityLink
- **
- ** This class implements a link object which can be placed on a linked
- ** list, and can hold a timer or priority value.
- ********************************************************************************/
-
- #define kNormalPriority (((unsigned long)-1L) >> 1)
- #define kHighestPriority 0
- #define kLowestPriority ((unsigned long)-1L)
- #define kToLowerPriority 1
-
- class TPriorityLink : public TLink
- {
- public:
- TPriorityLink(BooleanParm);
- TPriorityLink(void* value);
- TPriorityLink(TLink* link, void* value);
- TPriorityLink();
-
- void SetPriority(unsigned long);
- unsigned long GetPriority() const;
-
- private:
- unsigned long fPriority;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TPriorityLink
- ----------------------------------------------------------------- */
-
- inline TPriorityLink::TPriorityLink(BooleanParm val) : TLink(val)
- {}
-
- inline TPriorityLink::TPriorityLink()
- {
- fPriority = kNormalPriority;
- }
-
- inline TPriorityLink::TPriorityLink(TLink* link, void* value) :
- TLink(link, value)
- {
- fPriority = kNormalPriority;
- }
-
- inline TPriorityLink::TPriorityLink(void* value) : TLink(value)
- {
- fPriority = kNormalPriority;
- }
-
- inline void TPriorityLink::SetPriority(unsigned long pri)
- {
- fPriority = pri;
- }
-
- inline unsigned long TPriorityLink::GetPriority() const
- {
- return fPriority;
- }
-
- /*******************************************************************************
- ** CLASS TSimpleList
- **
- ** This class implements a simple linked list, which can have objects added
- ** at the front or the back of the list.
- ********************************************************************************/
-
- #define kTSimpleListID "!$slst,1.2"
-
- class TSimpleList : public TCollection
- {
- friend class TListIterator;
-
- public:
- _CDECL TSimpleList();
- _CDECL TSimpleList(TMemoryPool*);
- _CDECL TSimpleList(TSimpleList*);
- virtual ~_CDECL TSimpleList();
-
- // TCollection overrides
-
- virtual TIterator* _CDECL CreateIterator(TStandardPool*);
-
- virtual void* _CDECL Remove(const TMatchObject&);
- virtual Boolean _CDECL Remove(void*);
- virtual void* _CDECL Member(const TMatchObject&);
- virtual Boolean _CDECL Member(const void*);
-
- // New methods
-
- virtual TLink* _CDECL MemberLink(const void*);
- virtual TLink* _CDECL MemberLink(const TMatchObject&);
- virtual TLink* _CDECL RemoveLink(void*);
- virtual TLink* _CDECL RemoveLink(const TMatchObject&);
-
- virtual TLink* _CDECL FirstLink() const;
- virtual TLink* _CDECL LastLink() const;
- virtual TLink* _CDECL RemoveFirstLink();
- virtual TLink* _CDECL RemoveLastLink();
- virtual void _CDECL AddLinkFirst(TLink*);
- virtual void _CDECL AddLinkLast(TLink*);
-
- virtual void* _CDECL First() const;
- virtual void* _CDECL Last() const;
- virtual void* _CDECL RemoveFirst();
- virtual void* _CDECL RemoveLast();
- virtual OSErr _CDECL AddFirst(void*);
- virtual OSErr _CDECL AddLast(void*);
-
- void SetLinkPool(TMemoryPool*);
- TMemoryPool* GetLinkPool() const;
-
- protected:
- virtual OSErr _CDECL PrivateAdd(void*, long);
- virtual void _CDECL KillAll(BooleanParm ifDel, PointerType);
- virtual TLink* _CDECL PrivateFind(const void*, const TMatchObject*, TLink**) const;
-
- private:
- TSimpleList(const TSimpleList&);
- void operator=(const TSimpleList&);
-
- protected:
-
- TLink* fList;
- TLink* fLastInList;
- TMemoryPool* fLinkPool;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TSimpleList
- ----------------------------------------------------------------- */
-
- inline void TSimpleList::SetLinkPool(TMemoryPool* thePool)
- {
- fLinkPool = thePool;
- }
-
- inline TMemoryPool* TSimpleList::GetLinkPool() const
- {
- return fLinkPool;
- }
-
- /*******************************************************************************
- ** CLASS TLinkedList
- **
- ** This class adds the ability to do things with a linked list based on
- ** "after" or "before" rules.
- ********************************************************************************/
-
- #define kTLinkedListID "slm:coll$llst,1.2"
-
- class TLinkedList : public TSimpleList
- {
- public:
- _CDECL TLinkedList();
- _CDECL TLinkedList(TMemoryPool*);
- _CDECL TLinkedList(TSimpleList*);
- virtual ~_CDECL TLinkedList();
-
- // New methods
-
- virtual void* _CDECL After(const void* obj) const;
- virtual void* _CDECL After(const TMatchObject&) const;
- virtual void* _CDECL Before(const void* obj) const;
- virtual void* _CDECL Before(const TMatchObject&) const;
-
- virtual Boolean _CDECL AddLinkAfter(TLink*, const TMatchObject&);
- virtual Boolean _CDECL AddLinkAfter(TLink*, const void* obj);
- virtual Boolean _CDECL AddLinkBefore(TLink*, const TMatchObject&);
- virtual Boolean _CDECL AddLinkBefore(TLink*, const void* obj);
- virtual OSErr _CDECL AddAfter(void*, const TMatchObject&);
- virtual OSErr _CDECL AddAfter(void*, const void* obj);
- virtual OSErr _CDECL AddBefore(void*, const TMatchObject&);
- virtual OSErr _CDECL AddBefore(void*, const void* obj);
-
- private:
- TLinkedList(const TLinkedList&);
- void operator=(const TLinkedList&);
- };
-
- /*******************************************************************************
- ** CLASS TPriorityList
- **
- ** This class implements a list where objects are sorted in order of a
- ** priority.
- ********************************************************************************/
-
- #define kTPriorityListID "!$plst,1.2"
-
- class TPriorityList : public TSimpleList
- {
- public:
- _CDECL TPriorityList();
- _CDECL TPriorityList(TMemoryPool*);
- _CDECL TPriorityList(TPriorityList*);
- virtual ~_CDECL TPriorityList();
-
- // TLinkedList overrides
-
- virtual OSErr _CDECL AddFirst(void*);
- virtual OSErr _CDECL AddLast(void*);
- virtual void _CDECL AddLinkFirst(TLink*);
- virtual void _CDECL AddLinkLast(TLink*);
-
- // New methods
-
- virtual OSErr _CDECL AddPrioritized(void*, unsigned long pri);
- virtual void _CDECL AddLink(TPriorityLink*);
-
- private:
- TPriorityList(const TPriorityList&);
- void operator=(const TPriorityList&);
- virtual OSErr _CDECL PrivateAdd(void*, long);
- };
-
- /*******************************************************************************
- ** CLASS TListIterator
- **
- ** This iterator is used to iterate all collection classes descending from
- ** TSimpleList.
- ********************************************************************************/
-
- #define kTListIteratorID "!$litr,1.2"
-
- class TListIterator : public TIterator
- {
- public:
- _CDECL TListIterator(TSimpleList*);
- virtual ~_CDECL TListIterator();
-
- // TIterator Overrides
-
- virtual void _CDECL Reset();
- virtual void* _CDECL Next();
-
- virtual Boolean _CDECL IterationComplete() const;
- virtual Boolean _CDECL RemoveCurrentObject();
-
- // New methods
-
- virtual TLink* _CDECL GetCurrentLink() const;
- void SetList(TSimpleList*);
-
- private:
- TListIterator(const TListIterator&);
- void operator=(const TListIterator&);
-
- virtual TLink* _CDECL NextLink();
-
- TSimpleList* fList;
- TLink* fPrevLink;
- TLink* fCurLink;
- long fSeed;
- Boolean fComplete;
- Boolean fFiller;
- };
-
- /* -------------------------------------------------------------------------
- Inline methods for TListIterator
- ------------------------------------------------------------------------- */
-
- inline void TListIterator::SetList(TSimpleList* list)
- {
- fList = list;
- Reset();
- }
-
- /*******************************************************************************
- ** CLASS TArray
- **
- ** This class implements an array collection, where objects can be efficiently
- ** looked at by index, and are added to the end of the array. Deleting objects
- ** moves all higher-indexed objects down by 1 index number.
- ********************************************************************************/
-
- #define kTArrayID "slm:coll$arry,1.2"
-
- class TArray : public TCollection
- {
- friend class TArrayIterator;
-
- public:
- _CDECL TArray();
- _CDECL TArray(size_t size, TStandardPool* = NULL,
- int growBy = 0);
- virtual ~_CDECL TArray();
-
- virtual Boolean _CDECL IsValid() const;
-
- TStandardPool* GetGrowPool() const;
-
- // TCollection overrides
-
- virtual TIterator* _CDECL CreateIterator(TStandardPool*);
-
- virtual Boolean _CDECL Remove(void*);
- virtual void* _CDECL Remove(const TMatchObject&);
- virtual Boolean _CDECL Member(const void*);
- virtual void* _CDECL Member(const TMatchObject&);
-
- virtual void* _CDECL GetIndexedObject(size_t) const;
-
- private:
- TArray(const TArray&);
- void operator=(const TArray&);
- void _CDECL InitArray(size_t size, TStandardPool*, int growBy);
-
- protected:
- virtual void* _CDECL MemberIndex(const void*, const TMatchObject*, size_t*);
- virtual void* _CDECL PrivateRemove(void*, const TMatchObject*);
- virtual OSErr _CDECL PrivateAdd(void*, long);
- virtual void _CDECL KillAll(BooleanParm ifDel, PointerType);
- virtual Boolean _CDECL Grow();
-
- void** fArray; // memory allocated for the array
- size_t fSize; // current size of the array
- long fGrowBy; // size to grow by if array is full
- };
-
- /*******************************************************************************
- ** CLASS TArrayIterator
- **
- ** This class Iterates through a TArray collection
- ********************************************************************************/
-
- #define kTArrayIteratorID "slm:coll$aitr,1.2"
-
- class TArrayIterator : public TIterator
- {
- public:
- _CDECL TArrayIterator(TArray*);
- virtual ~_CDECL TArrayIterator();
-
- virtual void _CDECL Reset();
- virtual void* _CDECL Next();
-
- virtual Boolean _CDECL IterationComplete() const;
- virtual Boolean _CDECL RemoveCurrentObject();
-
- private:
- TArrayIterator(const TArrayIterator&);
- void operator=(const TArrayIterator&);
-
- private:
- TArray* fArray;
- size_t fCurIdx;
- long fSeed;
- Boolean fComplete;
- Boolean fFiller;
- };
-
- /*******************************************************************************
- ** Class THashList
- ********************************************************************************/
-
- #define kTHashListID "!$hsls,1.2"
-
- /* You need to do a LoadClass on kTHashListGrowerID if you want to call */
- /* THashList::Grow() at interrupt time at some later point. */
- #define kTHashListGrowerID "slm:supp$hlgrw,1.2"
-
- struct HashListInfo
- {
- size_t emptySlots; // number of empty slots in the hash list
- size_t singleSlots; // number of slots with only one entry
- size_t numChains; // number of slots with more than one entry
- size_t longestChain; // the longest chain
- size_t avgChain; // the average length of a chain
- };
-
- class THashList : public TCollection
- {
- friend class THashListIterator;
-
- protected:
- _CDECL THashList(BooleanParm);
-
- public:
- _CDECL THashList();
- _CDECL THashList(THashObject*,
- size_t initialSize,
- TMemoryPool* = NULL);
- virtual ~_CDECL THashList();
-
- virtual Boolean _CDECL IsValid() const;
-
- virtual OSErr _CDECL Grow(size_t newSize);
-
- OSErr Rehash();
-
- void SetHashObject(THashObject*);
- TMemoryPool* GetLinkPool() const;
- THashObject* GetHashObject() const;
- size_t GetTableSize() const;
- void SetLinkPool(TMemoryPool*);
-
- virtual void _CDECL GetHashListInfo(HashListInfo&) const;
-
- // TCollection Overrides
-
- virtual TIterator* _CDECL CreateIterator(TStandardPool*);
-
- virtual void* _CDECL Remove(const TMatchObject&);
- virtual Boolean _CDECL Remove(void*);
- virtual void* _CDECL Member(const TMatchObject&);
- virtual Boolean _CDECL Member(const void*);
-
- protected:
- virtual OSErr _CDECL PrivateAdd(void*, long);
- virtual void _CDECL KillAll(BooleanParm ifDel, PointerType);
-
- virtual void* _CDECL PrivateFind(const void*,
- const TMatchObject*,
- void** toDel);
-
- virtual Boolean _CDECL IsPrime(size_t num);
- virtual size_t _CDECL FixSize(size_t);
- unsigned long Hash(const void*);
-
- private:
- THashList(const THashList&);
- void operator=(const THashList&);
- void _CDECL InitHashList(THashObject*, TMemoryPool*,
- size_t);
- protected:
- THashObject* fHasher;
- TMemoryPool* fLinkPool;
- void** fTable;
- size_t fTableSize;
- void** fGrowTable;
- size_t fGrowTableSize;
- Boolean fGrowInProgress;
- Boolean fFiller;
- };
-
- /* -------------------------------------------------------------------------
- Inline methods for THashList
- ------------------------------------------------------------------------- */
-
- inline void THashList::SetHashObject(THashObject* obj)
- {
- fHasher = obj;
- }
-
- inline THashObject* THashList::GetHashObject() const
- {
- return fHasher;
- }
-
- inline void THashList::SetLinkPool(TMemoryPool* pool)
- {
- fLinkPool = pool;
- }
-
- inline TMemoryPool* THashList::GetLinkPool() const
- {
- return fLinkPool;
- }
-
- inline size_t THashList::GetTableSize() const
- {
- return fTableSize;
- }
-
- inline OSErr THashList::Rehash()
- {
- return Grow(GetTableSize());
- }
-
- /*******************************************************************************
- ** CLASS THashListIterator
- ********************************************************************************/
-
- #define kTHashListIteratorID "!$hsit,1.2"
-
- class THashListIterator : public TIterator
- {
- public:
- _CDECL THashListIterator(THashList*,
- TMatchObject* = NULL);
- virtual ~_CDECL THashListIterator();
-
- // TIterator Overrides
-
- virtual void _CDECL Reset();
- virtual void* _CDECL Next();
-
- virtual Boolean _CDECL IterationComplete() const;
- virtual Boolean _CDECL RemoveCurrentObject();
-
- protected:
- virtual Boolean _CDECL SetNextTable(int);
-
- private:
- THashListIterator (const THashListIterator&);
- void operator=(const THashListIterator&);
-
- protected:
- THashList* fList;
- long fSeed;
- void** fTable;
- size_t fTableSize;
- TLink* fLink;
- size_t fCell;
- short fTableNo;
- Boolean fFirst;
- Boolean fComplete;
- };
-
- /*******************************************************************************
- ** CLASS TOperation
- *******************************************************************************/
-
- #define kTOperationID "!$oper,1.2"
-
- #define kRemovedInProcess ((TPriorityLink*)-1L)
-
- class TOperation : public TDynamic
- {
- public:
- _CDECL TOperation();
- _CDECL TOperation(long creatorData);
- _CDECL TOperation(void* creatorPtr);
- _CDECL TOperation(ProcessProcPtr, long creatorData);
- _CDECL TOperation(ProcessProcPtr, void* creatorPtr);
- _CDECL TOperation(const TOperation&);
- virtual ~_CDECL TOperation();
-
- TPriorityLink* GetLink();
-
- virtual void _CDECL Reset();
- virtual void _CDECL Process();
-
- Boolean WasRemovedInProcess() const;
- void ClearRemovedInProcess();
- void SetDeleteWhenDone();
- Boolean IsBeingRerun() const;
-
- void SetProcessProc(ProcessProcPtr);
- ProcessProcPtr GetProcessProc() const;
-
- // Timer and Priority are just 2 different ways
- // of looking at the same field.
-
- void SetTime(const TTime&);
- void SetTime(unsigned long msecs);
- void SetPriority(unsigned long pri);
- unsigned long GetTime() const;
- unsigned long GetPriority() const;
-
- // CreatorData and CreatorPtr are just 2 different ways
- // of looking at the same field.
-
- void* GetCreatorPtr() const;
- long GetCreatorData() const;
- void SetCreatorPtr(void*);
- void SetCreatorData(long);
-
- #if GENERATING68K
- GlobalWorld GetSavedGlobalWorld() const;
- void SetSavedGlobalWorld(GlobalWorld);
- #endif
-
- TLibraryManager* GetSavedClient() const;
- void SetSavedClient(TLibraryManager*);
-
- private:
-
- ProcessProcPtr fProc;
- union
- {
- void* fPtr;
- long fLong;
- } fCreatorData; // Storage for the Creator
- TPriorityLink fProcessLink;
- #if GENERATING68K
- GlobalWorld fSavedWorld;
- #else
- TLibraryManager* fSavedClient;
- #endif
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TOperation
- ----------------------------------------------------------------- */
-
- inline TPriorityLink* TOperation::GetLink()
- {
- return &fProcessLink;
- }
-
- inline Boolean TOperation::WasRemovedInProcess() const
- {
- return fProcessLink.GetNext() == kRemovedInProcess;
- }
-
- inline void TOperation::ClearRemovedInProcess()
- {
- fProcessLink.SetNext(NULL);
- }
-
- inline Boolean TOperation::IsBeingRerun() const
- {
- return fProcessLink.GetPriority() != 0;
- }
-
- inline void TOperation::SetDeleteWhenDone()
- {
- fProcessLink.SetNext(kRemovedInProcess);
- }
-
- inline unsigned long TOperation::GetTime() const
- {
- return fProcessLink.GetPriority();
- }
-
- inline unsigned long TOperation::GetPriority() const
- {
- return fProcessLink.GetPriority();
- }
-
- inline void TOperation::SetTime(unsigned long msec)
- {
- fProcessLink.SetPriority(msec);
- }
-
- inline void TOperation::SetProcessProc(ProcessProcPtr proc)
- {
- fProc = proc;
- }
-
- inline void TOperation::SetPriority(unsigned long pri)
- {
- fProcessLink.SetPriority(pri);
- }
-
- inline void* TOperation::GetCreatorPtr() const
- {
- return fCreatorData.fPtr;
- }
-
- inline void TOperation::SetCreatorPtr(void* data)
- {
- fCreatorData.fPtr = data;
- }
-
- inline long TOperation::GetCreatorData() const
- {
- return fCreatorData.fLong;
- }
-
- inline void TOperation::SetCreatorData(long data)
- {
- fCreatorData.fLong = data;
- }
-
- inline ProcessProcPtr TOperation::GetProcessProc() const
- {
- return fProc;
- }
-
- #if GENERATING68K
-
- inline GlobalWorld TOperation::GetSavedGlobalWorld() const
- {
- return fSavedWorld;
- }
-
- inline void TOperation::SetSavedGlobalWorld(GlobalWorld world)
- {
- fSavedWorld = world;
- }
-
- inline TLibraryManager* TOperation::GetSavedClient() const
- {
- if (fSavedWorld != kInvalidWorld)
- return GetClientFromWorld(fSavedWorld);
- else
- return NULL;
- }
-
- inline void TOperation::SetSavedClient(TLibraryManager* client)
- {
- if (client != NULL)
- fSavedWorld = client->GetGlobalWorld();
- else
- fSavedWorld = kInvalidWorld;
- }
-
- #else
-
- inline TLibraryManager* TOperation::GetSavedClient() const
- {
- return fSavedClient;
- }
-
- inline void TOperation::SetSavedClient(TLibraryManager* client)
- {
- fSavedClient = client;
- }
-
- #endif
-
- /*******************************************************************************
- ** CLASS TScheduler
- **
- ** This is the base class for all schedulers. It allows for scheduling
- ** TOperations and removing them from the scheduling queue.
- *******************************************************************************/
-
- #define kTSchedulerID "!$sked,1.2"
-
- class TScheduler : public TDynamic
- {
- protected:
- _CDECL TScheduler();
-
- public:
- virtual ~_CDECL TScheduler();
-
- virtual Boolean _CDECL Remove(TOperation*) = 0;
- virtual TOperation* _CDECL Remove(const TMatchObject&) = 0;
- virtual TOperation* _CDECL RemoveNext() = 0;
- virtual Boolean _CDECL IsEmpty() const = 0;
-
- virtual void _CDECL Schedule(TOperation*) = 0;
- virtual void _CDECL Run() = 0;
-
- #if GENERATING68K
- Boolean IsSchedulerWorldValid() const;
- GlobalWorld GetSchedulerWorld() const;
- void SetSchedulerWorld(GlobalWorld);
- #endif
-
- Boolean IsSchedulerClientValid() const;
- TLibraryManager* GetSchedulerClient() const;
- void SetSchedulerClient(TLibraryManager*);
- protected:
- #if GENERATING68K
- GlobalWorld fSchedulerWorld;
- #else
- TLibraryManager* fSchedulerClient;
- #endif
- };
-
- /* -------------------------------------------------------------------------
- Inline Methods for class TScheduler
- ------------------------------------------------------------------------- */
-
- #if GENERATING68K
-
- inline GlobalWorld TScheduler::GetSchedulerWorld() const
- {
- return fSchedulerWorld;
- }
-
- inline void TScheduler::SetSchedulerWorld(GlobalWorld world)
- {
- fSchedulerWorld = world;
- }
-
- inline Boolean TScheduler::IsSchedulerWorldValid() const
- {
- return fSchedulerWorld != kInvalidWorld;
- }
-
- inline TLibraryManager* TScheduler::GetSchedulerClient() const
- {
- if (fSchedulerWorld != kInvalidWorld)
- return GetClientFromWorld(fSchedulerWorld);
- else
- return NULL;
- }
-
- inline void TScheduler::SetSchedulerClient(TLibraryManager* client)
- {
- if (client != NULL)
- fSchedulerWorld = client->GetGlobalWorld();
- else
- fSchedulerWorld = kInvalidWorld;
- }
-
- inline Boolean TScheduler::IsSchedulerClientValid() const
- {
- return GetSchedulerClient() != NULL;
- }
-
- #else
-
- inline TLibraryManager* TScheduler::GetSchedulerClient() const
- {
- return fSchedulerClient;
- }
-
- inline void TScheduler::SetSchedulerClient(TLibraryManager* client)
- {
- fSchedulerClient = client;
- }
-
- inline Boolean TScheduler::IsSchedulerClientValid() const
- {
- return fSchedulerClient != NULL;
- }
-
- #endif
-
- /*******************************************************************************
- ** CLASS TPriorityScheduler
- **
- ** This class implements a scheduler which simply insures processing
- ** of the TOperations by Priority.
- *******************************************************************************/
-
- #define kTPrioritySchedulerID "!$prsk,1.2"
-
- class TPriorityScheduler : public TScheduler
- {
- public:
- _CDECL TPriorityScheduler(); // autoRun default to false
- _CDECL TPriorityScheduler(BooleanParm ifAutoRun);
- virtual ~_CDECL TPriorityScheduler();
-
- virtual Boolean _CDECL IsValid() const;
-
- // Returns non-zero if an Operation is removed
- virtual Boolean _CDECL Remove(TOperation*);
- virtual TOperation* _CDECL Remove(const TMatchObject&);
- virtual TOperation* _CDECL RemoveNext();
- virtual Boolean _CDECL IsEmpty() const;
-
- // Default implementation processes TOperations on the
- // linked list until it is empty, but insures that 2
- // threads are not doing it at the same time. In
- // Non-AutoRun mode, anything scheduled after "Run"
- // is called will not Run until "Run" is called again.
- virtual void _CDECL Run();
-
- // Default implementation just throws the TOperation on
- // the linked list. If 'ifAutoRun' was set, the Run
- // method is called. Otherwise, someone must manually
- // call Run().
- virtual void _CDECL Schedule(TOperation*);
-
- virtual void _CDECL SetAutoRun(BooleanParm);
-
- protected:
- Boolean IsAutoRun() const;
- Boolean IsSchedulerDead() const;
- void SetSchedulerDead();
-
- TPriorityList fList;
- short fBusy;
- short fFlags;
- };
-
- /* -------------------------------------------------------------------------
- Inline methods for TPriorityScheduler
- ------------------------------------------------------------------------- */
-
- inline Boolean TPriorityScheduler::IsAutoRun() const
- {
- return fFlags & 1;
- }
-
- inline Boolean TPriorityScheduler::IsSchedulerDead() const
- {
- return fFlags < 0;
- }
-
- inline void TPriorityScheduler::SetSchedulerDead()
- {
- fFlags = -1;
- }
-
- /*******************************************************************************
- ** CLASS TSerialScheduler
- **
- ** This class implements a scheduler which simply insures FIFO processing
- ** of the TOperations. It is the same as a TPriorityScheduler, but
- ** sets the priority of the TOperation to kNormalPriority before
- ** scheduling.
- *******************************************************************************/
-
- #define kTSerialSchedulerID "!$srsk,1.2"
-
- class TSerialScheduler : public TPriorityScheduler
- {
- public:
- _CDECL TSerialScheduler(); // autoRun default to false
- _CDECL TSerialScheduler(BooleanParm ifAutoRun);
- virtual ~_CDECL TSerialScheduler();
-
- virtual void _CDECL Schedule(TOperation*);
- };
-
- /*******************************************************************************
- ** CLASS TThreadScheduler
- **
- ** This class implements a lightweight 'thread' task. In the Macintosh
- ** implementation, it is a TPriorityScheduler.
- *******************************************************************************/
-
- #define kTThreadSchedulerID "slm:sked$thsk,1.2"
-
- class TThreadScheduler : public TPriorityScheduler
- {
- public:
-
- _CDECL TThreadScheduler();
- virtual ~_CDECL TThreadScheduler();
-
- virtual void _CDECL Schedule(TOperation*);
-
- protected:
- virtual void _CDECL Run();
-
- private:
- void* fData;
- };
-
- /*******************************************************************************
- ** CLASS TTaskScheduler
- **
- ** This class implements a heavy-weight task which can interface to
- ** the operating system. In the Macintosh, it schedules TOperations to
- ** run at System Task time.
- *******************************************************************************/
-
- #define kTTaskSchedulerID "!$task,1.2"
-
- class TTaskScheduler : public TPriorityScheduler
- {
- public:
- _CDECL TTaskScheduler();
- _CDECL TTaskScheduler(unsigned long priority,
- BooleanParm runToEmpty = false);
- virtual ~_CDECL TTaskScheduler();
-
- virtual void _CDECL Schedule(TOperation*);
-
- virtual void _CDECL SetPriority(unsigned long);
- void _CDECL SetRunToEmpty(Boolean);
-
- protected:
- void _CDECL ProcessCalled();
-
- virtual void _CDECL Run();
-
- private:
- void _CDECL InitTaskScheduler(unsigned long);
-
- protected:
- TOperation fOperation;
-
- private:
- ProcPtr fSystem;
- void* fData;
- };
-
- /* -------------------------------------------------------------------------
- Inline methods for TTaskScheduler
- ------------------------------------------------------------------------- */
-
- inline void TTaskScheduler::SetRunToEmpty(Boolean runToEmpty)
- {
- SetAutoRun(runToEmpty);
- }
-
- /*******************************************************************************
- ** CLASS TInterruptScheduler
- **
- ** This class is used by all interrupt service routines to process
- ** incoming data. All layers above the interrupt service routines
- ** expect to be able to do any processing they want without fear of
- ** interrupts being locked out. That's what this scheduler insures.
- *******************************************************************************/
-
- #define kTInterruptSchedulerID "slm:sked$insk,1.2"
-
-
- class TInterruptScheduler : public TPriorityScheduler
- {
- public:
-
- _CDECL TInterruptScheduler();
- _CDECL TInterruptScheduler(TScheduler*, unsigned long priority);
- virtual ~_CDECL TInterruptScheduler();
-
- virtual Boolean _CDECL IsValid() const;
-
- virtual void _CDECL Schedule(TOperation*);
-
- protected:
- virtual void _CDECL Run();
-
- private:
- void InitializeInterruptScheduler(TScheduler*, unsigned long);
-
- private:
- void* fData;
- };
-
- /*******************************************************************************
- ** CLASS TTimeScheduler
- **
- ** This class implements a scheduler which will process TOperations
- ** when a requested amount of time has expired.
- *******************************************************************************/
-
- #define kMaxScheduledTime ((unsigned long)-1L)
-
- #define kTTimeSchedulerID "slm:sked$skti,1.2"
-
-
- class TTimeScheduler : public TScheduler
- {
- public:
- _CDECL TTimeScheduler();
- _CDECL TTimeScheduler(void* data);
- _CDECL TTimeScheduler(TScheduler*, unsigned long priority);
- virtual ~_CDECL TTimeScheduler();
-
- virtual Boolean _CDECL IsValid() const;
-
- virtual Boolean _CDECL Remove(TOperation*);
- virtual TOperation* _CDECL Remove(const TMatchObject&);
- virtual TOperation* _CDECL RemoveNext();
- virtual void _CDECL Schedule(TOperation*);
- virtual Boolean _CDECL IsEmpty() const;
-
- virtual Boolean _CDECL Reschedule(TOperation*, unsigned long time);
- virtual void _CDECL SetAutoReschedule(BooleanParm);
-
- virtual Boolean _CDECL DeleteInProcessOperation(TOperation* op);
- virtual Boolean _CDECL RerunInProcessOperation(TOperation* op);
-
- protected:
- virtual void _CDECL Run();
- virtual Boolean _CDECL ProcessTimerEvent();
- virtual TOperation* _CDECL PrivateRemove(TOperation*, const TMatchObject*);
- virtual TPriorityLink* _CDECL GetNextOperation(void*);
- virtual void _CDECL ProcessOperation();
- void* GetData() const;
-
- private:
- void InitializeTimeScheduler(TScheduler*, unsigned long);
-
- private:
- void* fData;
- unsigned short fTime;
- Boolean fDead;
- char fIfProcessing;
- TPriorityLink* fList;
- TSimpleList fReadyList;
-
- protected:
- long fSeed;
-
- private:
- Boolean fBusy;
- Boolean fFiller;
- };
-
- /* -------------------------------------------------------------------------
- Inline methods for TTimeScheduler
- ------------------------------------------------------------------------- */
-
- inline void* TTimeScheduler::GetData() const
- {
- return fData;
- }
-
-
- /*******************************************************************************
- ** CLASS TNotifier
- **
- ** This class and its subclasses are used for asynchronous notification
- ** of events.
- ********************************************************************************/
-
- #define kTNotifierID "!$noti,1.2"
-
- class TNotifier : public TDynamic
- {
- public:
- _CDECL TNotifier();
- virtual ~_CDECL TNotifier();
-
- virtual void _CDECL Notify(EventCode, OSErrParm = kNoError,
- void* = NULL) = 0;
-
- protected:
- #if GENERATING68K
- GlobalWorld fWorld; // global world when contructed
- #else
- TLibraryManager* fClient; // current client when constructed
- #endif
- };
-
- /*******************************************************************************
- ** CLASS TProcNotifier
- **
- ** This class is the base class for Notifiers that call a "C" procedure
- ** for notification. If the "refPtr" is left NULL, it will be replaced
- ** with a pointer to the TProcNotifier itself.
- *******************************************************************************/
-
- #define kTProcNotifierID "!$pnot,1.2"
-
- class TProcNotifier : public TNotifier
- {
- public:
- _CDECL TProcNotifier(NotifyProcPtr, void* refPtr = NULL);
- _CDECL TProcNotifier(const TProcNotifier&);
- virtual ~_CDECL TProcNotifier();
-
- virtual void _CDECL Notify(EventCode, OSErrParm = kNoError,
- void* notifyData = NULL);
-
- private:
- NotifyProcPtr fProc;
- void* fPtr;
- };
-
- /*******************************************************************************
- ** CLASS TMethodNotifier
- **
- ** This class is the base class for Notifiers that call a method in an object.
- *******************************************************************************/
-
- #define kTMethodNotifierID "!$mnot,1.2"
-
- class TMethodNotifier : public TNotifier
- {
- public:
- //
- // We pass an extra long parameter that is always set to -1 when SCpp clients
- // use the TMethodNotifier constructor. This is because SCpp method pointers
- // are always 4 byte pointers (sometimes to a "thunk") while CFront uses
- // 8 byte mptrs to determine the method. By having SCpp clients pass the -1
- // flag, the TMethodNotifier constructor is able to tell what kind of
- // method ponter is being passed to it and call it properly.
- //
- #ifdef __SC__
- _CDECL TMethodNotifier(TDynamic*, NotifyMethodPtr, long = -1);
- #else
- _CDECL TMethodNotifier(TDynamic*, NotifyMethodPtr);
- #endif
- _CDECL TMethodNotifier(const TMethodNotifier&);
- virtual ~_CDECL TMethodNotifier();
-
- virtual void _CDECL Notify(EventCode, OSErrParm = kNoError,
- void* notifyData = NULL);
-
- TDynamic* GetObject() const;
-
- private:
- TDynamic* fObject;
- unsigned short fOffset;
- signed short fIndex;
- NotifyProcPtr fMethod;
- };
-
- /* -----------------------------------------------------------------
- Inlines for TMethodNotifier
- ----------------------------------------------------------------- */
-
- inline TDynamic* TMethodNotifier::GetObject() const
- {
- return fObject;
- }
-
- /*******************************************************************************
- ** CLASS TMemoryPool
- **
- ** This is the abstract class from which memory allocators should
- ** descend.
- ********************************************************************************/
-
- struct PoolInfo
- {
- size_t fFreeBytes;
- size_t fLargestBlock;
- size_t fMaxUsage;
- size_t fCurSize;
- };
-
- #define kTMemoryPoolID "!$pool,1.2"
-
- extern "C" void* NewPool(size_t, size_t, ZoneType, MemoryType);
- extern "C" void* NewPoolWithZone(size_t, size_t, void*, MemoryType);
- extern "C" void DeletePool(void*);
-
- class TMemoryPool : public TDynamic
- {
- public:
- virtual ~_CDECL TMemoryPool();
-
- void* operator new(size_t size, size_t poolSize, ZoneType zType,
- MemoryType mType = kNormalMemory)
- { return NewPool(size, poolSize, zType, mType); }
- void* operator new(size_t size, size_t poolSize, void* zone,
- MemoryType mType = kNormalMemory)
- { return NewPoolWithZone(size, poolSize, zone, mType); }
- void* operator new(size_t size)
- { return NewPool(size, 0, kCurrentZone, kNormalMemory); }
- void operator delete(void* ptr)
- { DeletePool(ptr); }
-
- virtual void* _CDECL Allocate(size_t) = 0;
- virtual void* _CDECL Reallocate(void*, size_t) = 0;
- virtual void _CDECL Free(void*) = 0;
- virtual size_t _CDECL GetSize(void*) const = 0;
-
- virtual Boolean _CDECL CheckPool() const = 0;
- virtual void _CDECL GetPoolInfo(PoolInfo&) const;
- virtual void _CDECL TracePoolInfo() const;
-
- virtual Boolean _CDECL AddMemoryToPool(size_t);
- virtual void _CDECL DownsizePool();
- virtual size_t _CDECL GetLargestBlockSize() const = 0;
- size_t _CDECL GetCurrentPoolSize() const;
-
- void SetNotifier(TPoolNotifier*);
- TPoolNotifier* GetNotifier() const;
- void SetNotifyMarks(size_t low, size_t high = (size_t)-1L);
-
- static TMemoryPool* _CDECL RecoverPool(void*);
- static void* _CDECL AllocateMemory(size_t);
- static void* _CDECL AllocateMemory(TMemoryPool*, size_t);
- static void* _CDECL ReallocateMemory(void*, size_t);
- static void _CDECL FreeMemory(void*);
- static size_t _CDECL GetMemorySize(void*);
-
- protected:
- _CDECL TMemoryPool();
- virtual Boolean _CDECL PrivateAddMemoryToPool(void*, size_t) = 0;
- virtual Boolean _CDECL RemoveBlockFromPool(void*, size_t);
-
- private:
- TMemoryPool(const TMemoryPool&);
- void operator=(const TMemoryPool&);
-
- private:
- void* fMemList;
-
- protected:
- size_t fSize;
- size_t fLowMark;
- size_t fHighMark;
- size_t fMaxUsed;
- size_t fCurFree;
- void* fZone;
- unsigned char fMemType;
- short fFiller;
- TPoolNotifier* fNotifier;
- unsigned long fSeed;
- TMacSemaphore fSemaphore;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TMemoryPool
-
- The TMemoryPool inlines are located after the TStandardPool declaration
- below.
- ----------------------------------------------------------------- */
-
- /*******************************************************************************
- ** CLASS TStandardPool
- **
- ** The general purpose interrupt capable storage allocator.
- ********************************************************************************/
-
- #define kStandardPoolChunkOverhead 12
-
- #define kTStandardPoolID "!$stdp,1.2"
-
- class TStandardPool : public TMemoryPool
- {
- public:
- _CDECL TStandardPool();
- virtual ~_CDECL TStandardPool();
-
- virtual Boolean _CDECL IsValid() const;
-
- // TMemoryPool Overrides
-
- virtual void* _CDECL Allocate(size_t);
- virtual void* _CDECL Reallocate(void*, size_t);
- virtual void _CDECL Free(void*);
- virtual size_t _CDECL GetSize(void*) const;
- virtual Boolean _CDECL CheckPool() const;
- virtual size_t _CDECL GetLargestBlockSize() const;
-
- protected:
- virtual Boolean _CDECL PrivateAddMemoryToPool(void*, size_t);
- virtual Boolean _CDECL RemoveBlockFromPool(void*, size_t);
-
- _CDECL TStandardPool(size_t objSize);
-
- private:
- TStandardPool(const TStandardPool&);
- void operator=(const TStandardPool&);
-
- void _CDECL InitStandardPool(size_t objSize);
-
- Boolean _CDECL FreeChunks(void*, size_t);
- void _CDECL InternalFree(void*);
-
- protected:
- void* fList;
-
- private:
- void* fChunks[15];
- void* fFiller1;
- };
-
- /*******************************************************************************
- ** Inline Methods for TMemoryPool
- **
- ** We move them down here since at least one of them requires TStandardPool
- ** to already be defined.
- ********************************************************************************/
-
- inline void TMemoryPool::SetNotifyMarks(size_t low, size_t high)
- {
- fLowMark = low;
- fHighMark= high;
- }
-
- inline TPoolNotifier* TMemoryPool::GetNotifier() const
- {
- return fNotifier;
- }
-
- inline void TMemoryPool::SetNotifier(TPoolNotifier* nt)
- {
- fNotifier = nt;
- }
-
- inline size_t TMemoryPool::GetCurrentPoolSize() const
- {
- return fSize;
- }
-
- inline void* TMemoryPool::AllocateMemory(TMemoryPool* thePool, size_t size)
- {
- return thePool->Allocate(size);
- }
-
- inline void* TMemoryPool::AllocateMemory(size_t size)
- {
- return ((TMemoryPool*)::GetDefaultPool())->Allocate(size);
- }
-
- /*******************************************************************************
- ** CLASS TChunkyPool
- **
- ** This class implements a Pool where the memory returned is always
- ** the same size (a "chunk").
- ********************************************************************************/
-
- #define kChunkyPoolChunkOverhead 4
-
- #define kTChunkyPoolID "!$chkp,1.2"
-
- class TChunkyPool : public TMemoryPool
- {
- public:
- _CDECL TChunkyPool(size_t chunkSize);
- virtual ~_CDECL TChunkyPool();
-
- virtual Boolean _CDECL IsValid() const;
-
- // TMemoryPool Overrides
-
- virtual void* _CDECL Allocate(size_t size);
- virtual void* _CDECL Reallocate(void*, size_t);
- virtual void _CDECL Free(void*);
- virtual size_t _CDECL GetSize(void*) const;
- virtual Boolean _CDECL CheckPool() const;
- virtual size_t _CDECL GetLargestBlockSize() const;
-
- protected:
- virtual Boolean _CDECL PrivateAddMemoryToPool(void*, size_t);
- virtual Boolean _CDECL RemoveBlockFromPool(void*, size_t);
-
- public:
- // New methods
-
- size_t GetChunkSize() const;
- size_t GetNumberOfChunks() const;
-
- private:
- TChunkyPool(const TChunkyPool&);
- void operator=(const TChunkyPool&);
-
- size_t fNumberOfChunks;
- size_t fChunkSize;
- void* fFreeList;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TChunkyPool
- ----------------------------------------------------------------- */
-
- inline size_t TChunkyPool::GetChunkSize() const
- {
- return fChunkSize;
- }
-
- inline size_t TChunkyPool::GetNumberOfChunks() const
- {
- return fNumberOfChunks;
- }
-
- /*******************************************************************************
- ** CLASS TGrowOperation
- **
- ** See TPoolNotifier below
- ********************************************************************************/
-
- #define kTGrowOperationID "!$gwop,1.2"
-
- class TGrowOperation : public TOperation
- {
- public:
- _CDECL TGrowOperation();
- virtual ~_CDECL TGrowOperation();
-
- virtual void _CDECL Process();
-
- size_t fGrowBy;
- Boolean* fOpInUse;
- };
-
- /*******************************************************************************
- ** CLASS TPoolNotifier
- **
- ** Used by TMemoryPools so they can be notified when the pool reaches a low or
- ** high water mark. The TGrowOperation is not processed at interrupt time so it
- ** is always safe for it to grow the pool.
- ********************************************************************************/
-
- #define kTPoolNotifierID "!$plnt,1.2"
-
- class TPoolNotifier : public TNotifier
- {
- public:
- _CDECL TPoolNotifier(unsigned int growBy = 10,
- unsigned int minGrow = 128);
- virtual ~_CDECL TPoolNotifier();
-
- virtual void _CDECL Notify(EventCode, OSErrParm = kNoError, void* = NULL);
- virtual size_t _CDECL GrowBy(TMemoryPool*, size_t);
-
- private:
- void _CDECL InitNotifier(unsigned int, unsigned int);
-
- TGrowOperation fOperation;
- unsigned short fMinSize;
- unsigned short fGrowBy;
- Boolean fOpInUse;
- short fFiller;
- };
-
- /*******************************************************************************
- ** CLASS TArbitrator
- *******************************************************************************/
-
- #define kTArbitratorID "!$arbt,1.2"
-
- #define kRequestIDPrefix '?'
- #define kRequestIDPrefixSize 1
-
- typedef int TokenRequestType;
-
- #define kInvalidTokenRequest ((TokenRequestType)0)
- #define kRequestTokenRequest ((TokenRequestType)1)
- #define kExclusiveTokenRequest ((TokenRequestType)2)
- #define kSharedTokenRequest ((TokenRequestType)3)
-
- class TArbitrator : public THashObject
- {
- friend class TToken;
- public:
- _CDECL TArbitrator(TStandardPool* = NULL,
- size_t defSize = 0);
- virtual ~_CDECL TArbitrator();
-
- virtual OSErr _CDECL RegisterObject(const char* theID, void* theObject);
- virtual void* _CDECL UnregisterObject(const char* theID);
- virtual void* _CDECL LookupObject(const char* theID);
-
- virtual OSErr _CDECL RegisterToken(TToken*);
- virtual TToken* _CDECL GetToken(const char* theID, TokenRequestType);
-
- virtual TRequestToken* _CDECL PassiveRequest(const char* theID, TokenRequestType,
- TNotifier* = NULL,
- BooleanParm registerIfFirst = false);
- virtual TRequestToken* _CDECL ActiveRequest(const char* theID, TokenRequestType,
- TNotifier* = NULL,
- BooleanParm registerIfFirst = false);
- virtual TRequestToken* _CDECL GetRequest(const char* theID);
-
- virtual Boolean _CDECL NotifyOwners(TRequestToken* theRequest);
- virtual unsigned long _CDECL Hash(const void*) const;
-
- virtual TToken* _CDECL NewToken(const char* theID, void* = NULL);
-
- private: // methods
- virtual void _CDECL ReleaseToken(TToken* theToken);
- virtual TRequestToken* _CDECL NewRequestToken(const char* theID, TokenRequestType,
- TNotifier* = NULL);
- public:
- virtual void _CDECL UnregisterToken(TToken*);
-
- private: // data
- TCollection* fHashList;
- };
-
- /*******************************************************************************
- ** Class TTokenNotification (inline methods only)
- *******************************************************************************/
-
- class TTokenNotification
- {
- public:
- _CDECL TTokenNotification(TToken*, TRequestToken*);
- ~_CDECL TTokenNotification();
- TToken* GetToken();
- TRequestToken* GetRequestToken();
- private:
- TToken* fToken;
- TRequestToken* fRequestToken;
- };
-
- /* -----------------------------------------------------------------
- inline methods for TTokenNotification
- ----------------------------------------------------------------- */
-
- inline TToken* TTokenNotification::GetToken()
- {
- return fToken;
- }
-
- inline TRequestToken* TTokenNotification::GetRequestToken()
- {
- return fRequestToken;
- }
-
-
- /*******************************************************************************
- ** CLASS TToken
- *******************************************************************************/
-
- #define kTTokenID "!$tokn,1.2"
-
- class TToken : public TMatchObject
- {
- friend class TArbitrator;
-
- public:
- _CDECL TToken();
- _CDECL TToken(const char*);
- virtual ~_CDECL TToken();
-
- // TMatchObject methods
-
- virtual Boolean _CDECL IsEqual(const void*) const;
- virtual unsigned long _CDECL Hash() const;
-
- // new methods
-
- virtual Boolean _CDECL Get(TokenRequestType);
- virtual void _CDECL Release();
- virtual Boolean _CDECL Request(TRequestToken*);
- virtual Boolean _CDECL Notify(TRequestToken*);
- virtual TokenRequestType _CDECL GetRequestType() const;
-
- virtual void _CDECL SetID(const char*);
- const char* GetID() const;
-
- void* GetObject() const;
- void SetObject(void* theObject);
-
- TNotifier* GetNotifier() const;
- void SetNotifier(TNotifier*);
-
- long GetUseCount() const;
-
- private:
- virtual void _CDECL ReallyRelease();
-
- protected:
- TMacSemaphore fSemaphore;
- char* fID;
- void* fObject;
- TArbitrator* fArbitrator;
- long fUseCount;
- TNotifier* fNotifier;
- };
-
- /* -----------------------------------------------------------------
- inlines for TToken
- ----------------------------------------------------------------- */
-
- inline const char* TToken::GetID() const
- {
- return fID;
- }
-
- inline void* TToken::GetObject() const
- {
- return fObject;
- }
-
- inline void TToken::SetObject(void* theObject)
- {
- fObject = theObject;
- }
-
- inline TNotifier* TToken::GetNotifier() const
- {
- return fNotifier;
- }
-
- inline void TToken::SetNotifier(TNotifier* theNotifier)
- {
- fNotifier = theNotifier;
- }
-
- inline long TToken::GetUseCount() const
- {
- return fUseCount;
- }
-
- /*******************************************************************************
- ** CLASS TRequestToken
- *******************************************************************************/
-
- #define kTRequestTokenID "!$rqtk,1.2"
-
- class TRequestToken : public TToken
- {
- friend class TArbitrator;
-
- public:
- virtual ~_CDECL TRequestToken();
-
- // TMatchObject methods
-
- virtual Boolean _CDECL IsEqual(const void*) const;
- virtual unsigned long _CDECL Hash() const;
-
- // new methods
-
- virtual Boolean _CDECL Give(TToken* theToken);
- virtual TToken* _CDECL Exchange();
- virtual void _CDECL RequestAgain();
-
- virtual TokenRequestType _CDECL GetRequestType() const;
- virtual void _CDECL SetRequestType(TokenRequestType);
-
- Boolean IsTokenRegistered() const;
-
- private:
- _CDECL TRequestToken();
-
- private: // data
- Boolean fTokenRegistered;
- Boolean fActive;
- short fFiller;
- TokenRequestType fRequestType;
- };
-
- /* -----------------------------------------------------------------
- inlines for TRequestToken
- ----------------------------------------------------------------- */
-
- inline Boolean TRequestToken::IsTokenRegistered() const
- {
- return fTokenRegistered;
- }
-
-
- /*******************************************************************************
- ** class TClassInfo
- ********************************************************************************/
-
- #define kTClassInfoID "slm:supp$clif,1.2"
-
- class TClassInfo : public TIterator
- {
- friend class TLibraryManager;
-
- public:
- virtual ~_CDECL TClassInfo();
-
- // TIterator overrides
-
- virtual void _CDECL Reset();
- virtual void* _CDECL Next(); // safe to cast to TClassID* or char*
-
- virtual Boolean _CDECL IterationComplete() const;
- virtual Boolean _CDECL RemoveCurrentObject(); // do nothing instead
-
- // new methods
-
- void SetBaseClassID(const TClassID& classID);
-
- TClassID* GetClassID();
- virtual TClassID* _CDECL GetParentID(size_t idx = 0);
- TLibrary* GetLibrary() const;
- TLibraryFile* GetLibraryFile() const;
- unsigned short GetVersion() const;
- unsigned short GetMinVersion() const;
-
- Boolean GetNewObjectFlag() const;
- Boolean GetPreloadFlag() const;
- Boolean GetFunctionSetFlag() const;
- size_t GetSize() const;
-
- private:
- _CDECL TClassInfo();
-
- private:
- TClassID fBaseClassID;
- TClassID fClassID;
- TLibrary* fLibrary;
- TLibraryFile* fLibraryFile;
- unsigned short fVersion; // Class version
- unsigned short fMinVersion; // minimum supported version
- Boolean fNewObjectFlag;
- Boolean fPreloadFlag;
- Boolean fFunctionSetFlag;
- Boolean fFiller;
- size_t fSize;
- TClassID fParentID;
- };
-
- /* -------------------------------------------------------------------------
- inline methods of TClassInfo
- ------------------------------------------------------------------------- */
-
- inline void TClassInfo::SetBaseClassID(const TClassID& classID)
- {
- fBaseClassID = classID;
- Reset();
- }
-
- inline TClassID* TClassInfo::GetClassID()
- {
- return &fClassID;
- }
-
- inline TLibrary* TClassInfo::GetLibrary() const
- {
- return fLibrary;
- }
-
- inline TLibraryFile* TClassInfo::GetLibraryFile() const
- {
- return fLibraryFile;
- }
-
- inline unsigned short TClassInfo::GetVersion() const
- {
- return fVersion;
- }
-
- inline unsigned short TClassInfo::GetMinVersion() const
- {
- return fMinVersion;
- }
-
- inline Boolean TClassInfo::GetNewObjectFlag() const
- {
- return fNewObjectFlag;
- }
-
- inline Boolean TClassInfo::GetPreloadFlag() const
- {
- return fPreloadFlag;
- }
-
- inline Boolean TClassInfo::GetFunctionSetFlag() const
- {
- return fFunctionSetFlag;
- }
-
- inline size_t TClassInfo::GetSize() const
- {
- return fSize;
- }
-
- /**********************************************************************
- ** class TFileSpec
- **
- ** TFileSpec is a base class for specifying the location of a library
- ** file (TLibraryFile) in a file system or OS independent way. The
- ** subclasses contain the details and the base class is used to compare
- ** them or to pass them around without worry about the contents.
- **
- ** Currently only the TMacFileSpec is supported since this is how the
- ** SLM tracks library files on the Mac OS. There is a chance that in the
- ** furture it may track files under System 7.0 using TFileIDFileSpec so
- ** you should write your 7.0 code to handle either type. The
- ** IsFileSpecTypeSupported() routine will tell you if the specified
- ** TFileSpec subclass is supported.
- **
- ** Generally you don't need to be concerned with with TFileSpecs unless
- ** you are going to call RegisterLibraryFile(), RegisterLibraryFileFolder(),
- ** or TLibraryFile::GetFileSpec().
- ***********************************************************************/
-
- // Different types of TFileSpecs we can have.
- typedef unsigned int FileSpecType;
-
- #define kUnknownFileSpecType ((FileSpecType)0)
- #define kMacType ((FileSpecType)1)
- #define kFileIDType ((FileSpecType)2)
- #define kMaxFileSpecType ((FileSpecType)255)
-
- class TFileSpec;
- class TMacFileSpec;
- class TFileIDFileSpec;
-
- extern "C" Boolean IsFileSpecTypeSupported(FileSpecType);
- extern "C" Boolean CompareFileSpecs(const void* f1, const void* f2);
-
- class TFileSpec
- {
- public:
- void* operator new(size_t size, TMemoryPool *thePool)
- { return SLMNewOperator(size, thePool); }
- void* operator new(size_t size)
- { return SLMNewOperator(size, NULL); }
- void operator delete(void* obj, size_t)
- { SLMDeleteOperator(obj); }
-
- FileSpecType GetType() const;
- unsigned char GetSize() const;
-
- // compare operators
-
- Boolean operator==(const TFileSpec&) const;
- Boolean operator!=(const TFileSpec&) const;
-
- // cast operators
-
- operator const TMacFileSpec&() const;
- operator const TFileIDFileSpec&() const;
-
- unsigned char fType;
- unsigned char fSize;
- };
-
- inline FileSpecType TFileSpec::GetType() const
- {
- return fType;
- }
-
- inline unsigned char TFileSpec::GetSize() const
- {
- return fSize;
- }
-
- //
- // compare operators
- //
-
- inline Boolean TFileSpec::operator==(const TFileSpec& fileSpec) const
- {
- return (CompareFileSpecs(&fileSpec, this));
- }
-
- inline Boolean TFileSpec::operator!=(const TFileSpec& fileSpec) const
- {
- return (!CompareFileSpecs(&fileSpec, this));
- }
-
- //
- // cast operators
- //
-
- inline TFileSpec::operator const TMacFileSpec&() const
- {
- return *(const TMacFileSpec*)this;
- }
-
- inline TFileSpec::operator const TFileIDFileSpec&() const
- {
- return *(const TFileIDFileSpec*)this;
- }
-
-
- /**********************************************************************
- ** class TMacFileSpec
- **
- ** TMacFileSpec keeps track of the file by using an file name, volume
- ** refNum, and directory id. When newing a TMacFileSpec, you must
- ** pass the length of the file name (not including the length byte)
- ** to the new operator.
- ***********************************************************************/
-
- extern "C" void InitMacFileSpec(TMacFileSpec *spec, int vRefNum, long parID, const Str63 name);
-
- class TMacFileSpec : public TFileSpec
- {
- public:
- TMacFileSpec(const TMacFileSpec&);
- TMacFileSpec(int vRefNum, long parID, const Str63 name);
-
- void* operator new(size_t, size_t fileNameLen, TMemoryPool *thePool = NULL)
- {
- return SLMNewOperator(
- (sizeof(TMacFileSpec) -
- sizeof(Str63) +
- fileNameLen+1), thePool);
- }
- void* operator new(size_t size)
- { return SLMNewOperator(size, NULL); }
-
- void operator delete(void* obj)
- { SLMDeleteOperator(obj); }
-
- short fVRefNum; // volume refNum of volume file is on
- long fParID; // dirID of the folder file is in
- Str63 fName; // name of the file
- };
-
- inline TMacFileSpec::TMacFileSpec(const TMacFileSpec& fileSpec)
- {
- InitMacFileSpec(this, fileSpec.fVRefNum, fileSpec.fParID, fileSpec.fName );
- }
-
- inline TMacFileSpec::TMacFileSpec(int vRefNum, long parID, const Str63 name)
- {
- InitMacFileSpec(this, vRefNum, parID, name);
- }
-
-
- /**********************************************************************
- ** class TFileIDFileSpec
- **
- ** TFileIDFileSpec keeps track of library files by fileID and vRefNum.
- ***********************************************************************/
-
- // Some macros to make accessing fields without doing a cast easier
- #define GetFileIDFromFileSpec(x) (((const TFileIDFileSpec&)x).fFileID)
- #define GetVRefNumFromFileSpec(x) (((const TFileIDFileSpec&)x).fVRefNum)
-
- extern "C" void InitFileIDFileSpec(TFileIDFileSpec *spec, int vRefNum, long fileID);
-
- class TFileIDFileSpec : public TFileSpec
- {
- public:
- TFileIDFileSpec(const TFileIDFileSpec&);
- TFileIDFileSpec(int vRefNum, long fileID);
-
- short fVRefNum; // volume refNum
- long fFileID; // FileID
- };
-
- inline TFileIDFileSpec::TFileIDFileSpec(const TFileIDFileSpec& fileSpec)
- {
- InitFileIDFileSpec(this, GetVRefNumFromFileSpec(fileSpec),
- GetFileIDFromFileSpec(fileSpec));
- }
-
- inline TFileIDFileSpec::TFileIDFileSpec(int vRefNum, long fileID)
- {
- InitFileIDFileSpec(this, vRefNum, fileID);
- }
-
- /*******************************************************************************
- ** Class TLibraryFile
- **
- ** Used mainly to get resources out of a library file. A "C" interface is also
- ** provided in TLibraryManagerUtilities.h
- *******************************************************************************/
-
- #define kTLibraryFileID "!$lfil,1.2"
-
- extern "C" TLibraryFile* GetLocalLibraryFile();
-
- class TLibraryFile : public TDynamic
- {
- protected:
- virtual ~_CDECL TLibraryFile();
- _CDECL TLibraryFile();
-
- // This is the old prelight/postflight that we need to keep around so 1.0
- // clients will still work. SLM 1.1 clients should never call it. Use the
- // new calls further below
-
- #if GENERATING68K
- virtual OSErr _CDECL OldPreflight(short& savedRefNum) = 0;
- virtual OSErr _CDECL OldPostflight(short savedRefNum) = 0;
- #endif
-
- public:
- virtual Ptr _CDECL GetSharedResource(ResType, int theID, OSErr* = NULL) = 0;
- virtual Ptr _CDECL GetSharedIndResource(ResType, int index, OSErr* = NULL) = 0;
- virtual Ptr _CDECL GetSharedNamedResource(ResType, const char* name,
- OSErr* = NULL) = 0;
-
- virtual void _CDECL ReleaseSharedResource(Ptr) = 0;
- virtual long _CDECL CountSharedResources(ResType) = 0;
-
- virtual size_t _CDECL GetSharedResourceUseCount(Ptr) = 0;
- virtual OSErr _CDECL GetSharedResourceInfo(Ptr, size_t* theSize = NULL,
- short* theID = NULL, ResType* = NULL,
- char* theName = NULL) = 0;
-
- virtual long _CDECL GetRefNum() const = 0;
- virtual TFileSpec* _CDECL GetFileSpec() const = 0;
-
- virtual OSErr _CDECL OpenLibraryFile() = 0;
- virtual OSErr _CDECL CloseLibraryFile() = 0;
-
- virtual OSErr _CDECL Preflight(long& savedRefNum) = 0;
- virtual OSErr _CDECL Postflight(long savedRefNum) = 0;
- };
-
- /*******************************************************************************
- ** CLASS TBitmap
- *******************************************************************************/
-
- #define kTBitmapID "slm:supp$bmap,1.2"
-
- class TBitmap : public TDynamic
- {
- public:
- _CDECL TBitmap(size_t numBits, TMemoryPool* pool);
- _CDECL TBitmap(void* bits, size_t nBits);
- virtual ~_CDECL TBitmap();
-
- virtual Boolean _CDECL IsValid() const;
-
- // NOTE: There is no ErrorChecking on these first 3 calls.
-
- virtual Boolean _CDECL SetBit(size_t bitnum);
- virtual Boolean _CDECL ClearBit(size_t bitnum);
- virtual Boolean _CDECL TestBit(size_t bitnum);
-
- // These return -1 if no free bits
-
- virtual long _CDECL SetFirstClearBit();
- virtual long _CDECL SetFirstClearBit(size_t butnum, size_t numbits);
-
- private:
- void InitBitmap(size_t numBits, TMemoryPool* pool);
- void InitBitmap(void* bits, size_t nBits);
-
- unsigned char* fBits;
- size_t fNumberBits;
- Boolean fIsNewd;
- Boolean fFiller;
- };
-
- /*******************************************************************************
- ** CLASS TFastRandom
- ********************************************************************************/
-
- #define kTFastRandomID "slm:supp$frnd,1.2"
-
- const unsigned long kMaxFastRandom = 1771874;
-
- class TFastRandom : public TDynamic
- {
- public:
- _CDECL TFastRandom();
- _CDECL TFastRandom(unsigned long seed);
- virtual ~_CDECL TFastRandom();
-
- virtual void _CDECL SetSeed(unsigned long seed);
- virtual void _CDECL SetSeed();
- unsigned long GetSeed() const;
-
- virtual unsigned long _CDECL GetRandom();
- virtual unsigned long _CDECL GetRandomNumber(unsigned long lo,
- unsigned long hi);
-
- protected:
- unsigned long fSeed;
- };
-
- /* -------------------------------------------------------------------------
- Inline method for TFastRandom
- ------------------------------------------------------------------------- */
-
- inline unsigned long TFastRandom::GetSeed() const
- {
- return fSeed;
- }
-
- /*******************************************************************************
- ** CLASS TSimpleRandom
- ********************************************************************************/
-
- #define kTSimpleRandomID "slm:supp$srnd,1.2"
-
- const unsigned long kMaxSimpleRandom = 2145740624;
-
- class TSimpleRandom : public TFastRandom
- {
- public:
- _CDECL TSimpleRandom();
- _CDECL TSimpleRandom(unsigned long seed);
- _CDECL TSimpleRandom(unsigned long im, unsigned long ia,
- unsigned long ic);
- virtual ~_CDECL TSimpleRandom();
-
- virtual unsigned long _CDECL GetRandom();
- virtual unsigned long _CDECL GetRandomNumber(unsigned long lo,
- unsigned long hi);
-
- protected:
- unsigned long fIM;
- unsigned long fIA;
- unsigned long fIC;
- };
-
- /*******************************************************************************
- ** CLASS TDoubleLong
- **
- ** Implements a TDynamic double long (64 bits). Normally this is used
- ** as a superclass for some other class which has a 64-bit value as its
- ** comparable/hashing value (the default hash value is the low 32-bits).
- *******************************************************************************/
-
- #define kTDoubleLongID "slm:supp$dbll,1.2"
-
- class TDoubleLong : public TMatchObject
- {
- public:
- _CDECL TDoubleLong(const TDoubleLong&);
- _CDECL TDoubleLong(unsigned long low, long hi);
- _CDECL TDoubleLong(long l);
- _CDECL TDoubleLong();
- virtual ~_CDECL TDoubleLong();
-
- virtual OSErr _CDECL Inflate(TFormattedStream&);
- virtual OSErr _CDECL Flatten(TFormattedStream&) const;
-
- virtual Boolean _CDECL IsEqual(const void*) const;
- virtual unsigned long _CDECL Hash() const;
-
- virtual double _CDECL ConvertToDouble() const;
- void GetWide(wide&) const;
-
- operator double() const;
- operator unsigned long() const;
-
- virtual TDoubleLong& _CDECL Add(const TDoubleLong&);
- virtual TDoubleLong& _CDECL Subtract(const TDoubleLong&);
- virtual TDoubleLong& _CDECL Multiply(const TDoubleLong&);
- virtual TDoubleLong& _CDECL Divide(const TDoubleLong&);
- virtual TDoubleLong& _CDECL Modulo(const TDoubleLong&);
- virtual TDoubleLong& _CDECL RShift(unsigned int);
- virtual TDoubleLong& _CDECL LShift(unsigned int);
- virtual TDoubleLong& _CDECL Negate();
- virtual short _CDECL Compare(const void*) const;
-
- TDoubleLong& operator=(const TDoubleLong&);
- TDoubleLong& operator+=(const TDoubleLong&);
- TDoubleLong& operator-=(const TDoubleLong&);
- TDoubleLong& operator*=(const TDoubleLong&);
- TDoubleLong& operator/=(const TDoubleLong&);
- TDoubleLong& operator%=(const TDoubleLong&);
- TDoubleLong& operator&=(const TDoubleLong&);
- TDoubleLong& operator|=(const TDoubleLong&);
- TDoubleLong& operator^=(const TDoubleLong&);
-
- TDoubleLong operator+(const TDoubleLong&) const;
- TDoubleLong operator-(const TDoubleLong&) const;
- TDoubleLong operator*(const TDoubleLong&) const;
- TDoubleLong operator/(const TDoubleLong&) const;
- TDoubleLong operator%(const TDoubleLong&) const;
- TDoubleLong operator&(const TDoubleLong&) const;
- TDoubleLong operator|(const TDoubleLong&) const;
- TDoubleLong operator^(const TDoubleLong&) const;
- TDoubleLong operator~() const;
- TDoubleLong operator-() const;
-
- TDoubleLong operator<<(unsigned int) const;
- TDoubleLong operator>>(unsigned int) const;
-
- Boolean operator>(const TDoubleLong&) const;
- Boolean operator<(const TDoubleLong&) const;
- Boolean operator<=(const TDoubleLong&) const;
- Boolean operator>=(const TDoubleLong&) const;
- Boolean operator==(const TDoubleLong&) const;
- Boolean operator!=(const TDoubleLong&) const;
-
- protected:
- long fHiBits;
- unsigned long fLoBits;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TDoubleLong
- ----------------------------------------------------------------- */
-
- inline TDoubleLong::operator unsigned long() const
- {
- return fLoBits;
- }
-
- inline TDoubleLong::operator double() const
- {
- return ConvertToDouble();
- }
-
- inline void TDoubleLong::GetWide(wide& tw) const
- {
- tw.hi = fHiBits;
- tw.lo = fLoBits;
- }
-
- inline TDoubleLong TDoubleLong::operator &(const TDoubleLong& val) const
- {
- return TDoubleLong(fLoBits & val.fLoBits, fHiBits & val.fHiBits);
- }
-
- inline TDoubleLong& TDoubleLong::operator =(const TDoubleLong& val)
- {
- fHiBits = val.fHiBits;
- fLoBits = val.fLoBits;
- return *this;
- }
-
- inline TDoubleLong& TDoubleLong::operator +=(const TDoubleLong& val)
- {
- return Add(val);
- }
-
- inline TDoubleLong& TDoubleLong::operator -=(const TDoubleLong& val)
- {
- return Subtract(val);
- }
-
- inline TDoubleLong& TDoubleLong::operator *=(const TDoubleLong& val)
- {
- return Multiply(val);
- }
-
- inline TDoubleLong& TDoubleLong::operator /=(const TDoubleLong& val)
- {
- return Divide(val);
- }
-
- inline TDoubleLong& TDoubleLong::operator %=(const TDoubleLong& val)
- {
- return Modulo(val);
- }
-
- inline TDoubleLong& TDoubleLong::operator &=(const TDoubleLong& val)
- {
- fHiBits &= val.fHiBits;
- fLoBits &= val.fLoBits;
- return *this;
- }
-
- inline TDoubleLong& TDoubleLong::operator |=(const TDoubleLong& val)
- {
- fHiBits |= val.fHiBits;
- fLoBits |= val.fLoBits;
- return *this;
- }
-
- inline TDoubleLong& TDoubleLong::operator ^=(const TDoubleLong& val)
- {
- fHiBits ^= val.fHiBits;
- fLoBits ^= val.fLoBits;
- return *this;
- }
-
- inline TDoubleLong TDoubleLong::operator +(const TDoubleLong& val) const
- {
- TDoubleLong temp(*this);
- (&temp)->Add(val);
- return temp;
- }
-
- inline TDoubleLong TDoubleLong::operator -(const TDoubleLong& val) const
- {
- TDoubleLong temp(*this);
- (&temp)->Subtract(val);
- return temp;
- }
-
- inline TDoubleLong TDoubleLong::operator *(const TDoubleLong& val) const
- {
- TDoubleLong temp(*this);
- (&temp)->Multiply(val);
- return temp;
- }
-
- inline TDoubleLong TDoubleLong::operator /(const TDoubleLong& val) const
- {
- TDoubleLong temp(*this);
- (&temp)->Divide(val);
- return temp;
- }
-
- inline TDoubleLong TDoubleLong::operator %(const TDoubleLong& val) const
- {
- TDoubleLong temp(*this);
- (&temp)->Modulo(val);
- return temp;
- }
-
- inline TDoubleLong TDoubleLong::operator |(const TDoubleLong& val) const
- {
- return TDoubleLong(fLoBits | val.fLoBits, fHiBits | val.fHiBits);
- }
-
- inline TDoubleLong TDoubleLong::operator ^(const TDoubleLong& val) const
- {
- return TDoubleLong(fLoBits ^ val.fLoBits, fHiBits ^ val.fHiBits);
- }
-
- inline TDoubleLong TDoubleLong::operator~() const
- {
- return TDoubleLong(~fLoBits, ~fHiBits);
- }
-
- inline TDoubleLong TDoubleLong::operator -() const
- {
- TDoubleLong temp(*this);
- (&temp)->Negate();
- return temp;
- }
-
- inline TDoubleLong TDoubleLong::operator >>(unsigned int val) const
- {
- TDoubleLong temp(*this);
- (&temp)->RShift(val);
- return temp;
- }
-
- inline TDoubleLong TDoubleLong::operator <<(unsigned int val) const
- {
- TDoubleLong temp(*this);
- (&temp)->LShift(val);
- return temp;
- }
-
- inline Boolean TDoubleLong::operator ==(const TDoubleLong& val) const
- {
- return fLoBits == val.fLoBits && fHiBits == val.fHiBits;
- }
-
- inline Boolean TDoubleLong::operator !=(const TDoubleLong& val) const
- {
- return fLoBits != val.fLoBits || fHiBits != val.fHiBits;
- }
-
- inline Boolean TDoubleLong::operator >(const TDoubleLong& val) const
- {
- return Compare(&val) > 0;
- }
-
- inline Boolean TDoubleLong::operator >=(const TDoubleLong& val) const
- {
- return Compare(&val) >= 0;
- }
-
- inline Boolean TDoubleLong::operator <(const TDoubleLong& val) const
- {
- return Compare(&val) < 0;
- }
-
- inline Boolean TDoubleLong::operator <=(const TDoubleLong& val) const
- {
- return Compare(&val) <= 0;
- }
-
- /*******************************************************************************
- ** CLASS THashDoubleLong
- **
- ** Class to hash a TDoubleLong. The 'const void*' parameter is a
- ** pointer to a TDoubleLong object.
- *******************************************************************************/
-
- #define kTHashDoubleLongID "slm:supp$hdbl,1.2"
-
- class THashDoubleLong : public THashObject
- {
- public:
- _CDECL THashDoubleLong();
- virtual ~_CDECL THashDoubleLong();
-
- virtual unsigned long _CDECL Hash(const void*) const;
- };
-
- /*******************************************************************************
- ** CLASS TTime
- **
- ** This is the superclass for all Time-related classes. Internally,
- ** all times are stored as microSeconds, and the casting operators
- ** for the TTime class return values converted to microseconds.
- *******************************************************************************/
-
- #define kTTimeID "slm:supp$time,1.2"
-
- class TTime : public TDoubleLong
- {
- public:
- _CDECL TTime();
- _CDECL TTime(unsigned long microseconds);
- _CDECL TTime(const TDoubleLong&);
- _CDECL TTime(const TTime&);
- virtual ~_CDECL TTime();
-
- void SetTime(const TTime&);
-
- void SetMicroseconds(unsigned long);
- virtual void _CDECL SetMilliseconds(unsigned long);
- virtual void _CDECL SetSeconds(unsigned long);
-
- unsigned long GetMicroseconds() const;
- virtual unsigned long _CDECL GetMilliseconds() const;
- virtual unsigned long _CDECL GetSeconds() const;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TTime
- ----------------------------------------------------------------- */
-
- inline void TTime::SetTime(const TTime& time)
- {
- fLoBits = time.fLoBits;
- fHiBits = time.fHiBits;
- }
-
- inline void TTime::SetMicroseconds(unsigned long val)
- {
- fLoBits = val;
- fHiBits = 0;
- }
-
- inline unsigned long TTime::GetMicroseconds() const
- {
- return fLoBits;
- }
-
- /*******************************************************************************
- ** CLASS TMicroseconds
- *******************************************************************************/
-
- #define kTMicrosecondsID "slm:supp$mics,1.2"
-
- class TMicroseconds : public TTime
- {
- public:
- _CDECL TMicroseconds();
- _CDECL TMicroseconds(unsigned long msecs);
- ~_CDECL TMicroseconds();
-
- operator unsigned long() const;
- virtual double _CDECL ConvertToDouble() const;
- operator double() const;
-
- private:
- TMicroseconds(const TMicroseconds&);
- void operator=(const TMicroseconds&);
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TMicroseconds
- ----------------------------------------------------------------- */
-
- inline TMicroseconds::operator unsigned long() const
- {
- return GetMicroseconds();
- }
-
- inline TMicroseconds::operator double() const
- {
- return ConvertToDouble();
- }
-
- /*******************************************************************************
- ** CLASS TMilliseconds
- *******************************************************************************/
-
- #define kTMillisecondsID "slm:supp$mils,1.2"
-
- class TMilliseconds : public TTime
- {
- public:
- _CDECL TMilliseconds();
- _CDECL TMilliseconds(unsigned long msecs);
- ~_CDECL TMilliseconds();
-
- operator unsigned long() const;
- virtual double _CDECL ConvertToDouble() const;
- operator double() const;
-
- private:
- TMilliseconds(const TMilliseconds&);
- void operator=(const TMilliseconds&);
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TMilliseconds
- ----------------------------------------------------------------- */
-
- inline TMilliseconds::operator unsigned long() const
- {
- return GetMilliseconds();
- }
-
- inline TMilliseconds::operator double() const
- {
- return ConvertToDouble();
- }
-
- /*******************************************************************************
- ** CLASS TSeconds
- *******************************************************************************/
-
- #define kTSecondsID "slm:supp$secs,1.2"
-
- class TSeconds : public TTime
- {
- public:
- _CDECL TSeconds();
- _CDECL TSeconds(unsigned long secs);
- ~_CDECL TSeconds();
-
- operator unsigned long() const;
- virtual double _CDECL ConvertToDouble() const;
- operator double() const;
-
- private:
- TSeconds(const TSeconds&);
- void operator=(const TSeconds&);
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TSeconds
- ----------------------------------------------------------------- */
-
- inline TSeconds::operator unsigned long() const
- {
- return GetSeconds();
- }
-
- inline TSeconds::operator double() const
- {
- return ConvertToDouble();
- }
-
- /*******************************************************************************
- ** CLASS TTimeStamp
- *******************************************************************************/
-
- #define kTTimeStampID "slm:supp$tstm,1.2"
-
- class TTimeStamp : public TTime
- {
- public:
- _CDECL TTimeStamp();
- virtual ~_CDECL TTimeStamp();
-
- virtual void _CDECL SetTimeStamp();
-
- private:
- TTimeStamp(const TTimeStamp&);
- void operator=(const TTimeStamp&);
- };
-
- /*******************************************************************************
- ** CLASS TStopwatch
- *******************************************************************************/
-
- #define kTStopwatchID "slm:supp$stpw,1.2"
-
- class TStopwatch : public TTimeStamp
- {
- public:
- _CDECL TStopwatch();
- virtual ~_CDECL TStopwatch();
-
- virtual void _CDECL Reset();
-
- virtual unsigned long _CDECL ElapsedMicroseconds() const;
- virtual unsigned long _CDECL ElapsedMilliseconds() const;
- virtual unsigned long _CDECL ElapsedSeconds() const;
-
- private:
- TStopwatch(const TStopwatch&);
- void operator=(const TStopwatch&);
- };
-
- /*******************************************************************************
- ** CLASS TTraceLog
- **
- ** An object for doing debug tracing with.
- ********************************************************************************/
-
- #define kTTraceLogID "slm:dbug$tlog,1.2"
-
- class TTraceLog : public TDynamic
- {
- public:
- _CDECL TTraceLog();
- virtual ~_CDECL TTraceLog();
-
- virtual void _CDECL Trace(char *formatStr, ...) const;
-
- // New methods
-
- Boolean IsTraceLogOn() const;
- void TraceLogOn();
- void TraceLogOff();
-
- virtual void _CDECL TraceFormatted(char* outstr) const = 0;
- virtual void _CDECL TraceUnformatted(void* argp) const;
-
- protected:
- void SetTracePool(TStandardPool*);
- TStandardPool* GetTracePool() const;
-
- private:
- TTraceLog(const TTraceLog&);
- void operator=(const TTraceLog&);
-
- Boolean fTracing;
- Boolean fFiller1;
-
- //
- // We blew it on GENERATING68K by not getting the fTracePool field aligned on
- // a long word boundary. Since it is accessed by inline methods, we can't
- // safely change its alignment. In order to make the object layout the
- // same for powerpc, we define the field as 2 shorts instead.
- //
- #if GENERATING68K
- TStandardPool* fTracePool;
- #else
- unsigned short fTracePoolHi;
- unsigned short fTracePoolLo;
- #endif
- short fFiller2;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TTraceLog
- ----------------------------------------------------------------- */
-
- inline void TTraceLog::SetTracePool(TStandardPool* pool)
- {
- #if GENERATING68K
- fTracePool = pool;
- #else
- fTracePoolHi = (unsigned short)((unsigned long)pool >> 16);
- fTracePoolLo = (unsigned short)((unsigned long)pool);
- #endif
- }
-
- inline TStandardPool* TTraceLog::GetTracePool() const
- {
- #if GENERATING68K
- return fTracePool;
- #else
- return (TStandardPool*)(fTracePoolHi << 16 | fTracePoolLo);
- #endif
- }
-
- inline Boolean TTraceLog::IsTraceLogOn() const
- {
- return fTracing;
- }
-
- inline void TTraceLog::TraceLogOn()
- {
- if (GetTracePool() != NULL)
- fTracing = true;
- }
-
- inline void TTraceLog::TraceLogOff()
- {
- fTracing = false;
- }
-
- /*******************************************************************************
- ** Some inlines that rely on other inlines so we just do them here to prevent
- ** circular dependency problems.
- ********************************************************************************/
-
- /* -------------------------------------------------------------------------
- Inline methods for TArray
- ------------------------------------------------------------------------- */
-
- inline TStandardPool* TArray::GetGrowPool() const
- {
- return (TStandardPool*)TMemoryPool::RecoverPool(fArray);
- }
-
- #endif
-
- #endif
-